package com.example.administrator.gplineview;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.fm.openinstall.OpenInstall;
import com.fm.openinstall.listener.AppWakeUpListener;
import com.fm.openinstall.model.AppData;
import com.fm.openinstall.model.Error;

import java.util.ArrayList;
import java.util.List;

public class FundPictureActivity extends AppCompatActivity implements AppWakeUpListener {

    private CstView mCtsView;
    private List<Point> mPoints1;
    private List<Point> mPoints2;
    private List<String> mLeft;
    private List<String> mRight;
    private List<String> mBottom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OpenInstall.getWakeUp(getIntent(), this);
        mCtsView = (CstView) findViewById(R.id.view);
        mLeft = new ArrayList<>();
        mRight = new ArrayList<>();
        mBottom = new ArrayList<>();
        mPoints1 = new ArrayList<>();
        mPoints2 = new ArrayList<>();
        mLeft.add("0%");
        mLeft.add("0.5%");
        mLeft.add("1%");
        mLeft.add("1.5%");
        mLeft.add("2%");
        mLeft.add("2.5%");
        mLeft.add("3%");

        mRight.add("1元");
        mRight.add("0.8元");
        mRight.add("0.6元");
        mRight.add("0.4元");
        mRight.add("0.2元");
        mRight.add("0元");

        mBottom.add("01-23");
        mBottom.add("02-10");
        mBottom.add("02-23");
        mBottom.add("03-08");
        mBottom.add("03-21");
        mBottom.add("04-05");

        mPoints1.add(new Point(0,5));
        mPoints1.add(new Point(0.2f,4.0f));
        mPoints1.add(new Point(0.5f,3.1f));
        mPoints1.add(new Point(0.9f,1.1f));
        mPoints1.add(new Point(1.1f,4.6f));
        mPoints1.add(new Point(1.3f,5.3f));
        mPoints1.add(new Point(1.5f,4.3f));
        mPoints1.add(new Point(1.7f,2.3f));
        mPoints1.add(new Point(1.9f,1.2f));
        mPoints1.add(new Point(2.3f,2.3f));
        mPoints1.add(new Point(2.5f,2.8f));
        mPoints1.add(new Point(2.7f,4.3f));
        mPoints1.add(new Point(3.1f,4.6f));
        mPoints1.add(new Point(3.3f,1.6f));
        mPoints1.add(new Point(3.5f,3.1f));
        mPoints1.add(new Point(3.7f,5.2f));
        mPoints1.add(new Point(4f,3.3f));
        mPoints1.add(new Point(4.3f,3.9f));
        mPoints1.add(new Point(4.6f,2.4f));
        mPoints1.add(new Point(4.8f,5.4f));
        mPoints1.add(new Point(5f,4.6f));
        mPoints1.add(new Point(5.3f,4.6f));
        mPoints1.add(new Point(5.5f,1.6f));

        mPoints2.add(new Point(0,4));
        mPoints2.add(new Point(0.5f,2.1f));
        mPoints2.add(new Point(0.9f,3.6f));
        mPoints2.add(new Point(1.1f,2.9f));
        mPoints2.add(new Point(1.3f,4.3f));
        mPoints2.add(new Point(1.6f,2.5f));
        mPoints2.add(new Point(1.9f,0.2f));
        mPoints2.add(new Point(2.3f,1.3f));
        mPoints2.add(new Point(2.4f,1.8f));
//        mPoints2.add(new Point(2.5f,4.7f));
        mPoints2.add(new Point(2.8f,1.3f));
        mPoints2.add(new Point(3f,5f));
        mPoints2.add(new Point(3.3f,2.1f));
        mPoints2.add(new Point(3.6f,4f));
//        mPoints2.add(new Point(3.8f,2.3f));
//        mPoints2.add(new Point(4f,2.3f));
//        mPoints2.add(new Point(4.2f,3.6f));
        mPoints2.add(new Point(4.4f,4.3f));
        mPoints2.add(new Point(4.6f,1.4f));
        mPoints2.add(new Point(4.8f,5.0f));
        mPoints2.add(new Point(5f,3.6f));
        mPoints2.add(new Point(5.3f,3.6f));
        mPoints2.add(new Point(5.5f,0.6f));

        mCtsView.setData(mLeft,mRight,mBottom,7,0);
        mCtsView.setXYValue(0,0,7,6);
//        mCtsView.setTex
        mCtsView.addLine(Color.RED, mPoints1);
        mCtsView.addLine(Color.YELLOW, mPoints2);
        mCtsView.setShowAnim(true);
    }

    @Override
    public void onWakeUpFinish(AppData appData, Error error) {
        if (error == null) {
            Log.d("MainActivity", "wakeup = " + appData.toString());
        } else {
            Log.d("MainActivity", "error : "+error.toString());
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        //此处要调用，否则App在后台运行时，会无法截获
        OpenInstall.getWakeUp(intent, this);
    }
}
